<style>
#SystemCountDiv{
	margin: 3vh 4vw;
}
#SystemCountListDiv{
	margin: 16px -1px;
}
#DailySumLabel{
	color: #555;
	margin-top: 32px;
}
</style>

<div id='SystemCountDiv'>
	<div id='SystemCountQueryDiv'></div>
	<div id='SystemCountListDiv'></div>
	<div id='DailySumLabel'>当日访问量：{{daily}}  实时访问量：{{realtime}}</div>
</div>

<script>
var updata = {
	daily: 0,
	filter: '',
	realtime: 0,
};

var vmdata = {
	title: {
		path: '模块路径',
		daily: centerText('今日统计', 'bold'),
		realtime: centerText('实时统计', 'bold'),
		mincost: centerText('最小耗时(微秒)', 'bold'),
		maxcost: centerText('最大耗时(微秒)', 'bold'),
		meancost: centerText('平均耗时(微秒)', 'bold')
	},
	check: function(data){
		$.each(data.list, function(idx, item){
			if (item.path == '[NOT FOUND]'){
				item.mincost = '<red>----</red>';
				item.maxcost = '<red>----</red>';
				item.meancost = '<red>----</red>';
				item.realtime = '<red>----</red>';
				item.path = '<red>' + item.path + '</red>';
				item.daily = '<red>' + item.daily + '</red>';
			}

			translateCountItem(item);
		});

		updata.realtime = data.realtime;
		updata.daily = data.daily;
	}
};

getVue('SystemCountDiv', updata);

var text = QueryWidget('SystemCountQueryDiv', '输入网页路径', '查询', function(){
	if (updata.filter == text.val()){
		listview.reload(true);
	}
	else{
		listview.page(0, true);
		updata.filter = text.val();
	}
});

var listview = new RecordListView('SystemCountListDiv', '/getcountlist', vmdata, function(){
	return {path: text.val(), host: getParameter('host'), port: getParameter('port')};
});

function translateCountItem(item){
	function color(val){
		if (val > 1000000) return '<red>' + val + '</red>';
		if (val > 100000) return '<purple>' + val + '</purple>';
		if (val > 50000) return '<blue>' + val + '</blue>';
		return '<green>' + val + '</green>';
	}

	for (key in item){
		var val = item[key];
		if (key == 'path') continue;
		if (key.indexOf('cost') > 0) val = color(val);
		item[key] = "<div style='text-align:center'>" + val + "</div>";
	}
}

setSingletonInterval('system_count_timer', 3000, listview.reload);
</script>